home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / freetype.zip / ttdisp.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-07  |  4KB  |  248 lines

  1. (* This unit is only used to display fonts in 640x480x16 graphics mode *)
  2. (* under both DOS and OS/2. It is only used by the programs            *)
  3. (* 'TESTTIME' and 'TTZOOM'                                             *)
  4. (* It is not part of the engine itself                                 *)
  5.  
  6. Unit TTDisp;
  7.  
  8. interface
  9.  
  10. uses TTTypes;
  11.  
  12. procedure SetGraphScreen;
  13.  
  14. procedure RestoreScreen;
  15.  
  16. procedure Display( var Buff; Line, Col : Int );
  17.  
  18. procedure Clear( Line, Col : Int );
  19.  
  20. var
  21.   Vio : PByteArray;
  22.  
  23. implementation
  24.  
  25. {$IFDEF OS2}
  26.  
  27.   uses Os2Base, Use32;
  28.  
  29.   {$IFDEF DYNAMIC_VERSION}
  30.     {$Dynamic System}
  31.     {$L VPRTL.LIB}
  32.   {$ENDIF}
  33.  
  34.   type
  35.     Ptr16Rec = record
  36.       Ofs,Sel: SmallWord;
  37.     end;
  38.  
  39.   var
  40.     OrgMode   : VioModeInfo;
  41.     VioBufOfs : Longint;
  42.     Status    : SmallWord;
  43.  
  44.   { BIOS Video Mode #13 }
  45.  
  46.   const
  47.     VioMode: VioModeInfo =
  48.      ( cb:     SizeOf(VioModeInfo);
  49.        fbType: vgmt_Other + vgmt_Graphics;
  50.        Color:  colors_16;
  51.        Col:    80;
  52.        Row:    35;
  53.        HRes:   640;
  54.        VRes:   480
  55.      );
  56.  
  57.     VioBuf: VioPhysBuf =
  58.      ( pBuf: Ptr($A0000);
  59.        cb:   64*1024
  60.      );
  61.  
  62.   { Restores screen to the original state }
  63.  
  64.   procedure RestoreScreen;
  65.   begin
  66.     VioSetMode(OrgMode, 0);
  67.   end;
  68.  
  69.   procedure SetGraphScreen;
  70.   begin
  71.     { Save original video mode }
  72.     OrgMode.cb := SizeOf(VioModeInfo);
  73.     VioGetMode(OrgMode, 0);
  74.  
  75.     { Set VGA 640x400x16 video mode }
  76.     if VioSetMode(VioMode, 0) <> 0 then Halt(5);
  77.  
  78.     { Get selector for physical video buffer }
  79.     if VioGetPhysBuf(VioBuf, 0) <> 0 then Halt(7);
  80.  
  81.     { Make flat pointer that points to the physical video buffer}
  82.     Ptr16Rec(VioBufOfs).Ofs := 0;
  83.     Ptr16Rec(VioBufOfs).Sel := VioBuf.Sel;
  84.     SelToFlat(Pointer(VioBufOfs));
  85.  
  86.     { Clear the screen. Unlike function 0 of the BIOS INT 10h }
  87.     { VioSetMode doesn't clear the screen.                    }
  88.     FillChar(Pointer(VioBufOfs)^,64*1024,0);
  89.     Vio := PByteArray(VioBufOfs);
  90.   end;
  91.  
  92.   procedure Display; assembler;
  93.   asm
  94.     push esi
  95.     push edi
  96.     push ebx
  97.     push ecx
  98.  
  99.     mov esi,[Buff]
  100.  
  101.     mov ecx,80
  102.     mov ebx,[Col]
  103.     mov eax,[Line]
  104.     dec eax
  105.     mul ecx
  106.  
  107.     mov edi,[VioBufOfs]
  108.     add edi,eax
  109.  
  110.     mov edx,[line]
  111.     add ebx,80
  112.    @1:
  113.     mov ecx,[col]
  114.     rep movsb
  115.     sub edi,ebx
  116.     dec edx
  117.     jnz @1
  118.  
  119.     pop ecx
  120.     pop ebx
  121.     pop edi
  122.     pop esi
  123.   end;
  124.  
  125.   procedure Clear; assembler;
  126.   asm
  127.     push edi
  128.     push ebx
  129.     push ecx
  130.     push ebp
  131.  
  132.     mov ecx,80
  133.     mov ebx,[Col]
  134.     mov eax,[Line]
  135.     dec eax
  136.     mul ecx
  137.  
  138.     mov edi,[VioBufOfs]
  139.     add edi,eax
  140.  
  141.     mov edx,[line]
  142.     mov ebp,ebx
  143.     add ebx,80
  144.     xor eax,eax
  145.    @1:
  146.     mov ecx,ebp
  147.    @2:
  148.     mov [edi],al
  149.     inc edi
  150.     dec cx
  151.     jnz @2
  152.     sub edi,ebx
  153.     dec dx
  154.     jnz @1
  155.  
  156.     pop ebp
  157.     pop ecx
  158.     pop ebx
  159.     pop edi
  160.     pop esi
  161.   end;
  162.  
  163. {$ELSE}
  164.  
  165.   procedure SetGraphScreen;
  166.   begin
  167.     asm
  168.       mov ax,$0012
  169.       int $10
  170.     end;
  171.     Vio := PByteArray( @Mem[$A000:0] );
  172.   end;
  173.  
  174.   procedure RestoreScreen; assembler;
  175.   asm
  176.     mov ax,$0003
  177.     int $10
  178.   end;
  179.  
  180.   procedure Display; assembler;
  181.   asm
  182.     push ds
  183.     push bp
  184.  
  185.     mov ax,$A000
  186.     mov es,ax
  187.  
  188.     lds si,[Buff]
  189.  
  190.     cld
  191.  
  192.     mov cx,80
  193.     mov bx,[col]
  194.     mov ax,[line]
  195.     dec ax
  196.     mul cx
  197.     mov di,ax
  198.     mov dx,[line]
  199.     mov bp,bx
  200.     add bx,80
  201.    @1:
  202.     mov cx,bp
  203.     rep movsb
  204.     sub di,bx
  205.     dec dx
  206.     jnz @1
  207.  
  208.     pop bp
  209.     pop ds
  210.   end;
  211.  
  212.   procedure Clear; assembler;
  213.   asm
  214.     push ds
  215.     push bp
  216.  
  217.     mov ax,$A000
  218.     mov es,ax
  219.  
  220.     cld
  221.  
  222.     mov cx,80
  223.     mov bx,[col]
  224.     mov ax,[line]
  225.     dec ax
  226.     mul cx
  227.     mov di,ax
  228.     mov dx,[line]
  229.     mov bp,bx
  230.     add bx,80
  231.     xor al,al
  232.    @1:
  233.     mov cx,bp
  234.     rep stosb
  235.     sub di,bx
  236.     dec dx
  237.     jnz @1
  238.  
  239.     pop bp
  240.     pop ds
  241.   end;
  242.  
  243. {$ENDIF}
  244.  
  245. begin
  246. end.
  247.  
  248.